package com.javen.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;  
  



import org.springframework.stereotype.Service;

import com.javen.dao.FoodMapper;
import com.javen.dao.OrderMapper;
import com.javen.dao.SellerMapper;
import com.javen.model.Food;
import com.javen.model.Order;
import com.javen.model.Seller;
import com.javen.service.UserService;
  
  
/**
 * @author 悟笙
 *
 * 2018年5月21日
 */
@Service("userService")  
public class UserServiceImpl implements UserService {  
    @Resource  
    private SellerMapper sellerMapper;
    @Resource  
    private FoodMapper foodMapper;
    @Resource  
    private OrderMapper orderMapper;
    /**
     * 获取所有的商家
     * @return List <Seller>
     */
    public List <Seller> getSellers() {
    	return sellerMapper.selectAll();
    }

    /**
     * 通过id获取商家
     * @return Seller
     */
	public Seller getSeller(Integer sellerId) {
		// TODO Auto-generated method stub
		return sellerMapper.selectByPrimaryKey(sellerId);
	}
	/**
     * 通过商家id获取该商家的所有的菜
     * @param sellerId
     * @return List<Food>
     */
	@Override
	public List<Food> getFoods(int sellerId) {
		// TODO Auto-generated method stub
		return foodMapper.selectAllBySellerId(sellerId);
	}
	/**
     * 通过菜id获取菜
     * @param sellerId
     * @return Food
     */
	@Override
	public Food getFood(int foodId) {
		// TODO Auto-generated method stub
		return foodMapper.selectByPrimaryKey(foodId);
	}
	/**
     * 通过菜id以及分类名获取菜
     * @param sellerId className
     * @return List<Food>
     */
	@Override
	public List<Food> getFoodsByClassName(int sellerId, String className) {
		// TODO Auto-generated method stub
		Map<String,Object> map = new HashMap();
		
		map.put("sellerId", sellerId);
		map.put("className", className);
		
		return foodMapper.selectAllByClassName(map);
	}
	/**
     * 添加订单
     * @param order
     * @return int
     */
	@Override
	public int addOrder(Order order) {
		// TODO Auto-generated method stub
		return orderMapper.insertSelective(order);
	}
	
}  
